let arr = [1, 2, 3, 4, 5]

let [a, b, c, d, e] = [1, 2, 3, 4, 5]

let [a, b, [c, d]] = [1, 2, [3, 4]]  // 1,2,3,4

let  [a, b, [c]] = [1, 2, [3, 4]] // 1 ,2 ,3

let [a , b, c] = [1, 2, [3, 4]] // 1,2,[3,4]

let [a, b, c, d =5] = [1, 2, [3, 4], 7] // 1,2,[3,4],7    d=5是默认值,这里属于惰性赋值

let user = {
  name: 'yk',
  age: 25
}

let {name, age} = user  // 对象是通过key去一一对应的,而数组是通过下标对应的

let {age: uage,name : uname} = user //  uage, uname是别名 后面要用别名操作

let str= 'imooc' 

let [a, b, c, d, e] = str // a, b, c, d, e 

function foo() {
  console.log(123);
}

let [a = foo()] = [1] //  a = 1  若[]为空, 那么log 123


//对参数的结构
function foo ({name, age, school = 'imooc'}) { 
  // 行参 可以赋默认值,没有传就是默认, 格式数组或者对象都要和传入的值对应
  console.log(name, age , school);
}

let obj = {
  name : 'yk',
  age: 25,
  school: 'xxx'
}

foo(obj)

function foo() {
  let obj = {name: 'yk', age: 25, school: 'xxx'}
  return obj 
}

let {yname, age} = foo()
console.log(yname, age);

// JSON  javascript 

let json = '{"a": "hello", "b": "world"}' // json 的对象结构
let {a, b} =JSON.parse(json)
console.log(a, b);

